const {fileUploadError,unSupportedFileType} = require('../constant/err.type')
const path = require('path')
class CommonController {
    async upload(ctx,next) {
        const {file} = ctx.request.files
        const fileTypes = ['image/jpeg','image/png']
        if(file) {
            if(!fileTypes.includes((file.type))) {
                return  ctx.app.emit('error',unSupportedFileType,ctx)
            }
            ctx.body = {
                code: 0,
                msg: '文件上传成功',
                result: {
                    img: path.basename(file.path)
                }
            }
        }else {
            return ctx.app.emit('erroe',fileUploadError,ctx)
        }
    }
}

module.exports = new CommonController()